function primeSummation(n) {
    let dp = new Array(n + 1);
    dp.fill(dp, true);
    dp[0] = dp[1] = false;
    for (let i = 2; i * i <= n; i++) {
        if (dp[i]) {
            for (let j = i * i; j <= n; j += i) {
                dp[j] = false;
            }
        }
    }
    let sum = 0;
    for (let i = 2; i < n; i++)
        if (dp[i]) sum+=i;
    return sum;
}

console.log(primeSummation(2000000));